package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.Map;

import static org.mockito.Mockito.*;

class UserControllerTest1 {
    @Mock
    UserService userService;
    @Mock
    StringRedisTemplate stringRedisTemplate;
    @InjectMocks
    UserController userController;

    @BeforeEach
    void setUp() {
        MockitoAnnotations.openMocks(this);
    }

    @Test
    void testRegister() {
        when(userService.findByUserName(anyString())).thenReturn(new User());

        Result result = userController.register("username", "password");
        Assertions.assertEquals(new Result(Integer.valueOf(0), "message", "data"), result);
    }

    @Test
    void testLogin() {
        when(userService.findByUserName(anyString())).thenReturn(new User());

        Result<String> result = userController.login("username", "password");
        Assertions.assertEquals(new Result<String>(Integer.valueOf(0), "message", "data"), result);
    }

    @Test
    void testUserInfo() {
        when(userService.findByUserName(anyString())).thenReturn(new User());

        Result<User> result = userController.userInfo();
        Assertions.assertEquals(new Result<User>(Integer.valueOf(0), "message", new User()), result);
    }

    @Test
    void testUpdate() {
        Result result = userController.update(new User());
        Assertions.assertEquals(new Result(Integer.valueOf(0), "message", "data"), result);
    }

    @Test
    void testUpdateAvatar() {
        Result result = userController.updateAvatar("avatarUrl");
        Assertions.assertEquals(new Result(Integer.valueOf(0), "message", "data"), result);
    }

    @Test
    void testUpdatePwd() {
        when(userService.findByUserName(anyString())).thenReturn(new User());

        Result result = userController.updatePwd(Map.of("String", "String"), "token");
        Assertions.assertEquals(new Result(Integer.valueOf(0), "message", "data"), result);
    }
}

